package C;

import java.util.Scanner;

class UnionFindSet {
    int[] fa;

    public UnionFindSet(int n){
        this.fa = new int[n];
        for (int i = 0; i<n ;i++) {
            this.fa[i] = i;
        }
    }

    public int find(int x){
        if(this.fa[x] != x) {
            return this.fa[x] = this.find(this.fa[x]);
        }
        return x;
    }


    public void union(int x,int y){
        int x_fa = this.find(x);
        int y_fa = this.find(y);
        if(x_fa != y_fa) {
            this.fa[y_fa] = x_fa;
        }
    }

}


public class C3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m = sc.nextInt();
        if (m>=100000 || n < 1 || m < 1) {
            System.out.println("NULL");
            System.exit(0);
        }
        int[][] inputs = new int[m][3];
        for (int i=0;i<m;i++) {
            inputs[i][0] = sc.nextInt();
            inputs[i][1] = sc.nextInt();
            inputs[i][2] = sc.nextInt();
        }
        int a = 0,b = 0, c = 0;
        UnionFindSet union = new UnionFindSet(n+1);
        for (int i=0;i<m;i++) {
            a = inputs[i][0];
            b = inputs[i][1];
            c = inputs[i][2];

            int teamIndexA = union.find(a);
            int teamIndexB = union.find(b);
            if (c != 0 && c!= 1 || a < 1||b<1||a>n||b>n) {
                System.out.println("da pian zi");
                continue;
            }
            if (c == 0) {
                if (teamIndexA != teamIndexB) {
                    union.union(a,b);
                }
            } else if (c == 1){

                System.out.println(teamIndexA==teamIndexB?"we are a team":"we are not a team");

//                if (teamIndexA == teamIndexB) {
//                    System.out.println("we are a team");
//                } else {
//                    System.out.println("we are not a team");
//                }
            }



        }



//        for (int i=0;i<m;i++) {
//            System.out.println(inputs[i][0]);
//            System.out.println(inputs[i][1]);
//            System.out.println(inputs[i][2]);
//        }


    }
}
